﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InventoryProject.FrameWork;
using System.Data;

namespace InventoryProject.Setting
{
    public partial class dlgPopup : System.Web.UI.Page
    {
        PopupAccess _access;
        string LoginID;
        string Code,ctlID,ctlName;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginID = "admin"; // = Session["LogID"]
            if (Request.QueryString["Code"] != null)
            {
                Code = Request.QueryString["Code"].Trim();
                ctlID = Request.QueryString["ctlID"].Trim();
                ctlName = Request.QueryString["ctlName"].Trim();
            }
            //Insure that the __doPostBack() JavaScript method is created...
            this.ClientScript.GetPostBackEventReference(this, string.Empty);
            if (!IsPostBack)
            {

                LoadData(Code,"","");
            }
            else
            {
                if ((Request.Form["__EventTarget"] != null && Request.Form["__EventTarget"] == "myDblClick"))
                {
                    grdData.SelectedIndex = int.Parse(Request.Form["__EVENTARGUMENT"].ToString());
                    GridViewRow dr;
                    dr = grdData.SelectedRow;
                    
                    if (!ClientScript.IsStartupScriptRegistered("popup"))
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(),"popup", "UpdateParam('" + dr.Cells[0].Text + "','" + HttpUtility.HtmlDecode(dr.Cells[1].Text) +"','" + ctlID + "','" + ctlName + "')", true);
                    }
           
                }
            }
        }

        private void LoadData(string Code,string Type,string Value)
        {
            _access = new PopupAccess();
            DataTable dtData = _access.PopUp_Qry(Code, Type, Value);
            grdData.DataSource = dtData;
            grdData.DataBind();
        }

        protected void grdData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.color='red'";
                e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.color='black';";
                e.Row.Attributes.Add("ondblclick", "Javascript:__doPostBack('myDblClick','" + e.Row.RowIndex + "');");
            }
        }
    }
}